<template>
	<article class="page page-transcoding container">
		<h4 class="text-center">编码转换器</h4>
		<form class="content">
			<div class="row">
				<div class="col-4">
					<fieldset>
						<legend>配置选项</legend>
						<div class="fieldset-content">
							<div class="form-group funcs-wrapper">
								<div v-for="(btnGroup, gIndex) in btnGroupList" class="row btn-group-row" :key="gIndex">
									<div v-for="(btn, bIndex) in btnGroup" :class="[`col-${12 / btnGroup.length}`]" :key="bIndex">
										<button type="button" class="btn btn-block btn-sm"
											:class="[btn.callback === btnActive ? 'btn-success' : 'btn-secondary']" @click="btnItemClick(btn)">{{ btn.label }}</button>
									</div>
								</div>
							</div>
							<div class="form-group">
								<div class="form-group-sm">
									<x-button type="primary" block @click="result2content">将结果数据复制到原始数据</x-button>
								</div>
								<div class="form-group-sm">
									<x-button type="primary" block @click="conversion">转 换</x-button>
								</div>
							</div>
						</div>
					</fieldset>
				</div>
				<div class="col-8">
					<fieldset>
						<legend>数据处理</legend>
						<div class="fieldset-content">
							<div class="form-group textarea-wrapper">
								<textarea class="form-control" v-model.trim="content" rows="8" placeholder="原始数据"></textarea>
							</div>
							<div class="form-group row" v-if="btnActive === 'JSFuck'">
								<div class="col-6 form-check form-check-inline">
									<input class="form-check-input" type="checkbox" v-model="eval" @change="JSFuck">
									<label class="form-check-label">Eval Source</label>
								</div>
								<div class="col-6 form-check form-check-inline">
									<input class="form-check-input" type="checkbox" v-model="scope" @change="JSFuck">
									<label class="form-check-label">Run In Parent Scope</label>
								</div>
							</div>
							<div class="form-group row-flex" align="center" v-else-if="['jjEncode', 'jjDecode'].includes(btnActive)">
								<div class="row-flex-prefix">全局变量</div>
								<div class="row-flex-main"><input class="form-control" type="text" v-model="jjVar" /></div>
								<div class="row-flex-suffix">
									<div class="form-check form-check-inline">
										<input class="form-check-input" type="checkbox" v-model="palindrome">
										<label class="form-check-label">Palindrome</label>
									</div>
								</div>
							</div>
							<div class="form-group row-flex" align="center" v-else-if="['enKeyword', 'deKeyword'].includes(btnActive)">
								<div class="row-flex-prefix">Keyword</div>
								<div class="row-flex-main">
									<input class="form-control" type="text" v-model="keywordPassword" placeholder="不建议包含标点符号和数字" />
								</div>
							</div>
							<div class="form-group row-flex" align="center" v-else-if="['enVigenere', 'deVigenere'].includes(btnActive)">
								<div class="row-flex-prefix">Key</div>
								<div class="row-flex-main">
									<input class="form-control" type="text" v-model="vigenereKey" placeholder="不建议包含标点符号和数字" />
								</div>
							</div>
							<div class="form-group row-flex" align="center" v-else-if="['enGronsfeld', 'deGronsfeld'].includes(btnActive)">
								<div class="row-flex-prefix">Key</div>
								<div class="row-flex-main">
									<input class="form-control" type="text" v-model="gronsfeldKey" placeholder="0~9之间的数字序列，如:123654" />
								</div>
							</div>
							<div class="form-group row-flex" align="center" v-else-if="['enFo', 'deFo'].includes(btnActive)">
								<div class="row-flex-prefix">Key</div>
								<div class="row-flex-main">
									<input class="form-control" type="text" v-model="foKey" placeholder="箴言（可选）" />
								</div>
							</div>
							<div class="form-group row-flex" align="center" v-else-if="['enSimpleBase', 'deSimpleBase'].includes(btnActive)">
								<div class="row-flex-prefix">基数</div>
								<div class="row-flex-main">
									<input class="form-control" type="text" v-model="baseN" placeholder="请输入2~62之间的整数，如:2" />
								</div>
							</div>
							<div class="form-group" v-else-if="['enBrainfuck', 'deBrainfuck'].includes(btnActive)">
								<div class="form-check form-check-inline">
									<input class="form-check-input" type="checkbox" v-model="ng">
									<label class="form-check-label">ng extensions</label>
								</div>
							</div>
							<div class="form-group" v-else-if="btnActive === 'ppEncode'">
								<div class="text-grey">#!/usr/bin/perl -w</div>
							</div>
							<div class="form-group row-flex" align="center" v-else-if="['punyEncode', 'punyDecode'].includes(btnActive)">
								<div class="row-flex-prefix">编码类型</div>
								<div class="row-flex-main">
									<select class="form-control" v-model="punycoding">
										<option v-for="(v,i) in punycodingList" :key="i" :value="v.value">{{v.label}}</option>
									</select>
								</div>
							</div>
							<div class="form-group textarea-wrapper">
								<textarea class="form-control" v-model.trim="result" rows="8" placeholder="结果数据"></textarea>
							</div>
						</div>
					</fieldset>
				</div>
			</div>
			<!-- <div class="alert alert-secondary" role="alert">
				<div>1、escape不对“+”编码。但是网页在提交表单的时候，如果有空格，则会被转化为+字符。服务器处理数据的时候，会把+号处理成空格。所以，使用的时候要小心。</div>
				<div>2、encodeURI不会对“; / ? : @ & = + $ ,
					#”这些符号进行编码；而在encodeURIComponent中统统会被编码，二者编码规则是相同的。encodeURIComponent是对URI中的一个组件进行编码，不能用于全部的URL。</div>
				<div>3、Base16/Base32/Base64/MD5/SHA-1 相关函数使用的是npmjs上共享的 guless-converter 库。</div>
				<div>4、莫尔斯加密字符之间以空格分隔，“*Morse加密/解密”<strong class="text-danger">支持中文</strong>。</div>
				<div>5、JSFuck功能的代码是提取自jsfuck.com网站。</div>
			</div> -->
		</form>
	</article>
</template>

<script>
import jjencode from './jjencode.js'
import ppencode from './ppencode.js'
import a1z26 from './a1z26.js'
import keyword from './keyword.js'
// import BaseEx from 'base-ex'
const simplebig = require('./simplebig.js')
const punycode = global.require('punycode')
let BaseEx = global.BaseEx || {}
let utf7 = global.utf7 || {}
let de_Morse = global.de_Morse || {}
let en_Morse = global.en_Morse || {}
let JSFuck = global.JSFuck || {}
let uuencode = global.uuencode || {}
let xxencode = global.xxencode || {}
let bubblebabbler = global.bubblebabbler
let Vigenere = global.Vigenere
let gronsfeld = global.gronsfeld
let quotedPrintable = global.quotedPrintable
let togod = global.togod
let toman = global.toman
let utf8 = global.utf8
let converter = global.converter || {
	encode: global.encode,
	decode: global.decode,
	md5: global.md5,
	sha1: global.sha1,
}
const morseTable = {
	"A": ".-", "B": "-...", "C": "-.-.", "D": "-..", "E": ".", "F": "..-.", "G": "--.",
	"H": "....", "I": "..", "J": ".---", "K": "-.-", "L": ".-..", "M": "--", "N": "-.",
	"O": "---", "P": ".--.", "Q": "--.-", "R": ".-.", "S": "...", "T": "-", "U": "..-",
	"V": "...-", "W": ".--", "X": "-..-", "Y": "-.--", "Z": "--..",
	"0": "-----", "1": ".----", "2": "..---", "3": "...--", "4": "....-", "5": ".....",
	"6": "-....", "7": "--...", "8": "---..", "9": "----.", ".": ".-.-.-", ":": "---...",
	",": "--..--", ";": "-.-.-.", "?": "..--..", "=": "-...-", "'": ".----.", "/": "-..-.",
	"!": "-.-.--", "-": "-....-", "_": "..--.-", '"': ".-..-.", "(": "-.--.", ")": "-.--.-",
	"$": "...-..-", "&": "....", "@": ".--.-.", "Ñ": "--.--", " ": " ", "": ""
}

export default {
	name: 'transcoding',
	data() {
		return {
			content: '',
			result: '',
			btnActive: 'B2T',
			btnGroupList: [
				[{ label: '二进制to字符串', callback: 'B2T' }, { label: '字符串to二进制', callback: 'T2B' }],
				[{ label: '二进制to十进制', callback: 'B2D' }, { label: '十进制to二进制', callback: 'D2B' }],
				[{ label: '十进制to十六进制', callback: 'D2H' }, { label: '十六进制to十进制', callback: 'H2D' }],
				[{ label: 'HTML编码', callback: 'htmlEncode' }, { label: 'HTML解码', callback: 'htmlDecode' }],
				[{ label: 'escape编码', callback: 'escape' }, { label: 'unescape解码', callback: 'unescape' }],
				[{ label: 'encodeURI编码', callback: 'encodeURI' }, { label: 'decodeURI解码', callback: 'decodeURI' }],
				[{ label: 'encodeURIComponent', callback: 'encodeURIComponent' }, { label: 'decodeURIComponent', callback: 'decodeURIComponent' }],
				[{ label: 'Unicode编码', callback: 'enUnicode' }, { label: 'Unicode解码', callback: 'deUnicode' }],
				[{ label: 'GB2312编码', callback: 'encodeGb2312' }, { label: 'GB2312解码', callback: 'decodeGb2312' }],
				[{ label: 'Base16编码', callback: 'enBase16' }, { label: 'Base16解码', callback: 'deBase16' }], // 0-9,A-F共16个以及补位的“=”
				[{ label: 'Base32编码', callback: 'enBase32' }, { label: 'Base32解码', callback: 'deBase32' }], // A-Z,2-7共32个以及补位的“=”
				[{ label: 'Base58编码', callback: 'enBase58' }, { label: 'Base58解码', callback: 'deBase58' }],
				[{ label: 'Base64编码', callback: 'enBase64' }, { label: 'Base64解码', callback: 'deBase64' }], // a-z,A-Z,0-9,+,/共64个以及补位的“=”
				[{ label: 'Base85编码', callback: 'enBase85' }, { label: 'Base85解码', callback: 'deBase85' }],
				[{ label: 'Base91编码', callback: 'enBase91' }, { label: 'Base91解码', callback: 'deBase91' }],
				[{ label: 'Base2048编码', callback: 'enBase2048' }, { label: 'Base2048解码', callback: 'deBase2048' }],
				[{ label: 'BasePhi编码', callback: 'enBasePhi' }, { label: 'BasePhi解码', callback: 'deBasePhi' }],
				[{ label: 'SimpleBase编码', callback: 'enSimpleBase' }, { label: 'SimpleBase解码', callback: 'deSimpleBase' }],
				[{ label: 'AAEncode', callback: 'aaEncode' }, { label: 'AADecode', callback: 'aaDecode' }],
				[{ label: 'JJEncode', callback: 'jjEncode' }, { label: 'JJDecode', callback: 'jjDecode' }],
				[{ label: 'UUEncode', callback: 'uuEncode' }, { label: 'UUDecode', callback: 'uuDecode' }], // 取值32(空白)到95(底线),无小写字母
				[{ label: 'XXEncode', callback: 'xxEncode' }, { label: 'XXDecode', callback: 'xxDecode' }],
				[{ label: 'ppEncode', callback: 'ppEncode' }, { label: 'BubbleBabble', callback: 'bubbleBabble' }],
				[{ label: 'punyEncode', callback: 'punyEncode' }, { label: 'punyDecode', callback: 'punyDecode' }],
				[{ label: 'QuotedPrintable编码', callback: 'quotedPrintableEncode' }, { label: 'QuotedPrintable解码', callback: 'quotedPrintableDecode' }],
				[{ label: 'A1z26加密', callback: 'enA1z26' }, { label: 'A1z26解密', callback: 'deA1z26' }],
				[{ label: 'Ecoji编码', callback: 'enEcoji' }, { label: 'Ecoji解码', callback: 'deEcoji' }],
				[{ label: '关键字加密', callback: 'enKeyword' }, { label: '关键字解密', callback: 'deKeyword' }],
				[{ label: '维吉尼亚加密', callback: 'enVigenere' }, { label: '维吉尼亚解密', callback: 'deVigenere' }],
				[{ label: 'Gronsfeld加密', callback: 'enGronsfeld' }, { label: 'Gronsfeld解密', callback: 'deGronsfeld' }],
				[{ label: 'Morse加密', callback: 'enMorse' }, { label: 'Morse解密', callback: 'deMorse' }],
				[{ label: '*Morse加密', callback: 'myEnMorse' }, { label: '*Morse解密', callback: 'myDeMorse' }],
				[{ label: 'JSFuck', callback: 'JSFuck' }, { label: 'Run JSFuck', callback: 'RunJSFuck', immediate: true }],
				[{ label: 'Brainfuck加密', callback: 'enBrainfuck' }, { label: 'Brainfuck解密', callback: 'deBrainfuck' }],
				[{ label: 'Ook!加密', callback: 'enOok' }, { label: 'Ook!解密', callback: 'deOok' }],
				[{ label: '电脑键盘加密', callback: 'enKeyboard' }, { label: '电脑键盘解密', callback: 'deKeyboard' }],
				[{ label: '听佛讲经', callback: 'enFo' }, { label: '听佛解惑', callback: 'deFo' }],
				[{ label: '简体转繁体', callback: 's2t' }, { label: '繁体转简体', callback: 't2s' }],
				[{ label: 'MD5加密', callback: 'enMd5' }, { label: 'SHA-1加密', callback: 'enSha1' }],
				[{ label: '字符串倒序', callback: 'strRev' }, { label: '大小写转换', callback: 'toggleCase' }],
			],
			// 电脑键盘加密变量声明
			keyboard: 'QWERTYUIOPASDFGHJKLZXCVBNM',
			englishLetters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
			// 关键字加密变量声明
			keywordPassword: '',
			// 维吉尼亚加密变量声明
			vigenereKey: '',
			// Gronsfeld加密变量声明
			gronsfeldKey: '',
			// Brainfuck变量声明
			ng: false,
			BrainfuckObj: null,
			// JSFuck变量声明
			eval: true,
			scope: true,
			// SimpleBase变量声明
			baseN: '',
			// jjEncode变量声明
			jjVar: '$',
			palindrome: false,
			// punycode变量声明
			punycoding: '',
			punycodingList: [
				{value: '', label: '默认'},
				{value: 'asc-uni', label: 'ASCII/Unicode'},
				{value: 'ucs2', label: 'ucs2'},
			],
			// 与佛论禅
			foKey: ''
		}
	},
	computed: {
		morseTableRev() {
			let result = {}
			for (let key in morseTable) {
				result[morseTable[key]] = key
			}
			return result
		},
	},
	mounted() {
		utf7 = this.$sharedObject('utf7')
		uuencode = this.$sharedObject('uuencode')
		xxencode = this.$sharedObject('xxencode')
		bubblebabbler = this.$sharedObject('bubblebabbler')
		Vigenere = this.$sharedObject('Vigenere')
		gronsfeld = this.$sharedObject('gronsfeld')
	},
	methods: {
		btnItemClick(item) {
			if (item.immediate) {
				this[item.callback] && (this[item.callback])()
			} else {
				this.btnActive = item.callback
			}
		},
		result2content() {
			this.content = this.result
			this.result = ''
		},
		conversion() {
			this.result = ''
			this[this.btnActive] && (this[this.btnActive])()
		},
		// 按钮组函数
		B2T() {
			if (/\s/.test(this.content)) {
				let arr = this.content.split(' ')
				for (let i = 0; i < arr.length; i++) {
					this.result += String.fromCharCode(parseInt(arr[i], 2))
				}
			} else if (this.content.length % 8 === 0) {
				while (this.content) {
					this.result += String.fromCharCode(parseInt(this.content.substring(0, 8), 2))
					this.content = this.content.substring(8)
				}
			} else {
				this.$toast('待转换的内容与当前算法不匹配！')
			}
		},
		T2B() {
			let arr = []
			for (let i = 0; i < this.content.length; i++) {
				let item = this.content[i].charCodeAt().toString(2)
				arr.push(item)
			}
			this.result = arr.join(' ')
		},
		B2D() { this.result = parseInt(this.content, 2) },
		D2B() { this.result = parseInt(this.content).toString(2) },
		D2H() { this.result = parseInt(this.content).toString(16) },
		H2D() { this.result = parseInt(this.content, 16) },
		htmlEncode() { this.result = global.$('<div>').text(this.content).html() },
		htmlDecode() { this.result = global.$('<div>').html(this.content).text() },
		escape() { this.result = escape(this.content) },
		unescape() { this.result = unescape(this.content) },
		encodeURI() { this.result = encodeURI(this.content) },
		decodeURI() { this.result = decodeURI(this.content) },
		encodeURIComponent() { this.result = encodeURIComponent(this.content) },
		decodeURIComponent() { this.result = decodeURIComponent(this.content) },
		encodeGb2312() { this.result = this.$jstools.encodeGb2312(this.content) },
		decodeGb2312() { this.result = this.$jstools.decodeGb2312(this.content) },
		enUnicode() {
			let strArr = Array.from(this.content)
			let arr = []
			for (let i = 0; i < strArr.length; i++) {
				let item = strArr[i].codePointAt().toString(16).toUpperCase()
				arr.push(item)
			}
			this.result = '\\u' + arr.join('\\u')
		},
		deUnicode() {
			let arr = this.content.split('\\u')
			arr = arr.slice(1)
			for (let i = 0; i < arr.length; i++) {
				this.result += String.fromCodePoint(parseInt(arr[i], 16))
			}
		},
		enBase16() { this.result = converter.encode(this.content, 'base16') },
		deBase16() { this.result = converter.decode(this.content, 'base16') },
		enBase32() { this.result = converter.encode(this.content, 'base32') },
		deBase32() { this.result = converter.decode(this.content, 'base32') },
		enBase64() { this.result = converter.encode(this.content, 'base64') },
		deBase64() { this.result = converter.decode(this.content, 'base64') },
		enBase58() {
			let Base58 = new BaseEx.Base58()
			this.result = Base58.encode(this.content)
		},
		deBase58() {
			let Base58 = new BaseEx.Base58()
			let ab = Base58.decode(this.content)
			this.result = String.fromCharCode.apply(null, new Uint8Array(ab))
		},
		enBase85() {
			let Base85 = new BaseEx.Base85()
			this.result = Base85.encode(this.content)
		},
		deBase85() {
			let Base85 = new BaseEx.Base85()
			let ab = Base85.decode(this.content)
			this.result = String.fromCharCode.apply(null, new Uint8Array(ab))
		},
		enBase91() {
			let Base91 = new BaseEx.Base91()
			this.result = Base91.encode(this.content)
		},
		deBase91() {
			let Base91 = new BaseEx.Base91()
			let ab = Base91.decode(this.content)
			this.result = String.fromCharCode.apply(null, new Uint8Array(ab))
		},
		enBase2048() {
			let Base2048 = new BaseEx.Base2048()
			this.result = Base2048.encode(this.content)
		},
		deBase2048() {
			let Base2048 = new BaseEx.Base2048()
			let ab = Base2048.decode(this.content)
			this.result = String.fromCharCode.apply(null, new Uint8Array(ab))
		},
		enBasePhi() {
			let BasePhi = new BaseEx.BasePhi()
			this.result = BasePhi.encode(this.content)
		},
		deBasePhi() {
			let BasePhi = new BaseEx.BasePhi()
			let ab = BasePhi.decode(this.content)
			this.result = String.fromCharCode.apply(null, new Uint8Array(ab))
		},
		enSimpleBase() {
			let n = parseInt(this.baseN)
			if (!n) {
				this.$toast('请输入基数')
				return
			}
			if (n < 2 || n > 62) {
				this.$toast('基数须是2-62之间的整数')
				return
			}
			let SimpleBase = new BaseEx.SimpleBase(n)
			this.result = SimpleBase.encode(this.content)
		},
		deSimpleBase() {
			let n = parseInt(this.baseN)
			if (!n) {
				this.$toast('请输入基数')
				return
			}
			if (n < 2 || n > 62) {
				this.$toast('基数须是2-62之间的整数')
				return
			}
			let SimpleBase = new BaseEx.SimpleBase(n)
			let ab = SimpleBase.decode(this.content)
			this.result = String.fromCharCode.apply(null, new Uint8Array(ab))
		},
		uuEncode() { this.result = uuencode.encode(this.content) },
		uuDecode() { this.result = uuencode.decode(this.content) },
		xxEncode() { this.result = xxencode.encode(this.content) },
		xxDecode() { this.result = xxencode.decode(this.content) },
		aaEncode() { this.result = global.aaEncode(this.content) },
		aaDecode() { this.result = global.aaDecode(this.content) },
		quotedPrintableEncode() { this.result = quotedPrintable.encode(utf8.encode(this.content)) },
		quotedPrintableDecode() { this.result = utf8.decode(quotedPrintable.decode(this.content)) },
		jjEncode() { this.result = jjencode.jjEncode(this.jjVar, this.content, this.palindrome, true) },
		jjDecode() { this.result = jjencode.jjDecode(this.content) },
		ppEncode() { this.result = ppencode.ppEncode(this.content) },
		bubbleBabble() { this.result = bubblebabbler(this.content) },
		punyEncode() {
			if (this.punycoding === 'asc-uni') {
				this.result = punycode.toASCII(this.content)
			} else if (this.punycoding === 'ucs2') {
				let content = this.$jstools.jsonParse(this.content, [])
				this.result = punycode.ucs2.encode(content)
			} else {
				this.result = punycode.encode(this.content)
			}
		},
		punyDecode() {
			if (this.punycoding === 'asc-uni') {
				this.result = punycode.toUnicode(this.content)
			} else if (this.punycoding === 'ucs2') {
				this.result = JSON.stringify(punycode.ucs2.decode(this.content))
			} else {
				this.result = punycode.decode(this.content)
			}
		},
		enBrainfuck() {
			// eslint-disable-next-line no-undef
			if (!this.BrainfuckObj) { this.BrainfuckObj = new BrainFuckerJS() }
			this.result = this.BrainfuckObj.pretty_bf(this.content)
		},
		deBrainfuck() {
			// eslint-disable-next-line no-undef
			if (!this.BrainfuckObj) { this.BrainfuckObj = new BrainFuckerJS() }
			this.result = this.BrainfuckObj.out(this.content, null, this.ng)
		},
		enOok() {
			// eslint-disable-next-line no-undef
			if (!this.BrainfuckObj) { this.BrainfuckObj = new BrainFuckerJS() }
			let _result = this.BrainfuckObj.pretty_bf(this.content)
			this.result = _result.toOok()
		},
		deOok() {
			// eslint-disable-next-line no-undef
			if (!this.BrainfuckObj) { this.BrainfuckObj = new BrainFuckerJS() }
			let _result = this.content.toBrainfuck()
			this.result = this.BrainfuckObj.out(_result, null, false)
		},
		enMd5() { this.result = converter.md5(this.content) },
		enSha1() { this.result = converter.sha1(this.content) },
		enUtf7() { this.result = utf7.encode(this.content) },
		deUtf7() { this.result = utf7.decode(this.content) },
		enA1z26() { this.result = a1z26.encrypt(this.content) },
		deA1z26() { this.result = a1z26.decrypt(this.content) },
		enEcoji() {
			let Ecoji = new BaseEx.Ecoji()
			this.result = Ecoji.encode(this.content)
		},
		deEcoji() {
			let Ecoji = new BaseEx.Ecoji()
			let ab = Ecoji.decode(this.content)
			this.result = String.fromCharCode.apply(null, new Uint8Array(ab))
		},
		enKeyword() { this.result = keyword.encrypt(this.content, this.keywordPassword) },
		deKeyword() { this.result = keyword.decrypt(this.content, this.keywordPassword) },
		enVigenere() { this.result = Vigenere.encode(this.content, this.vigenereKey) },
		deVigenere() { this.result = Vigenere.decode(this.content, this.vigenereKey) },
		enGronsfeld() { this.result = gronsfeld.encrypt(this.gronsfeldKey, this.content) },
		deGronsfeld() { this.result = gronsfeld.decrypt(this.gronsfeldKey, this.content) },
		enMorse() { this.result = en_Morse(this.content) },
		deMorse() { this.result = de_Morse(this.content) },
		s2t() { this.result = simplebig.s2t(this.content) },
		t2s() { this.result = simplebig.t2s(this.content) },
		enFo() { this.result = togod(this.content) },
		deFo() { this.result = toman(this.content) },
		myDeMorse() {
			let result = ''
			let arr = this.content.split(' ')
			for (let i = 0; i < arr.length; i++) {
				if (arr[i] in this.morseTableRev) {
					result += this.morseTableRev[arr[i]]
				} else {
					result += String.fromCodePoint(parseInt(arr[i].replace(/-/g, '1').replace(/\./g, '0'), 2))
				}
			}
			this.result = result
		},
		myEnMorse() {
			let result = ''
			let arr = []
			let strArr = Array.from(this.content.toUpperCase())
			for (let i = 0; i < strArr.length; i++) {
				if (morseTable[strArr[i]]) {
					arr.push(morseTable[strArr[i]])
				} else {
					arr.push(strArr[i].codePointAt().toString(2).replace(/1/g, '-').replace(/0/g, '.'))
				}
			}
			result = arr.join(' ')
			this.result = result
		},
		enKeyboard() {
			this.content = this.content.toUpperCase()
			for (let i = 0; i < this.content.length; i++) {
				if (this.englishLetters.indexOf(this.content[i]) >= 0) {
					this.result += this.keyboard[this.englishLetters.indexOf(this.content[i])]
				} else {
					this.result += this.content[i]
				}
			}
		},
		deKeyboard() {
			this.content = this.content.toUpperCase()
			for (let i = 0; i < this.content.length; i++) {
				if (this.keyboard.indexOf(this.content[i]) >= 0) {
					this.result += this.englishLetters[this.keyboard.indexOf(this.content[i])]
				} else {
					this.result += this.content[i]
				}
			}
		},
		strRev() { this.result = this.content.split('').reverse().join('') },
		toggleCase() {
			let c = this.content[0].charCodeAt()
			if (c >= 65 && c <= 90) {
				this.result = this.content.toLowerCase()
			} else if (c >= 97 && c <= 122) {
				this.result = this.content.toUpperCase()
			}
		},
		JSFuck() { this.result = JSFuck.encode(this.content, this.eval, this.scope) },
		RunJSFuck() {
			if (this.btnActive !== 'JSFuck') {
				this.$toast('该功能仅配合JSFuck按钮使用')
				return
			}
			if (!this.result && this.content) {
				this.result = JSFuck.encode(this.content, this.eval, this.scope)
			}
			let value = global.eval(this.result)
			if (!this.eval) { global.eval(value) }
		},
	},
}
</script>

<style scoped lang="less">
@import "~@/assets/css/_mixins.less";
@import "~@/assets/css/_color.less";

.page-transcoding {
	display: flex;
	flex-direction: column;

	fieldset {
		height: 100%;
		.fieldset-content {
			height: calc(100% - 2em);
			display: flex;
			flex-direction: column;
			.funcs-wrapper {
				height: 0;
				flex-grow: 1;
				overflow: hidden auto;
			}
			.textarea-wrapper {
				height: 0;
				flex-grow: 1;
				textarea {
					height: 100%;
				}
			}
		}
	}

	.form-group-sm {
		&+.form-group-sm {
			margin-top: .5em;
		}
	}
	.form-check-inline {
		color: @colorGrey;
	}

	.content {
		height: 0;
		flex-grow: 1;
		overflow: hidden auto;
		& > .row {height: 100%;}

		.btn-group-row {
			margin-bottom: 2px;

			.col-6:first-child {
				padding-right: 1px;
			}

			.col-6:last-child {
				padding-left: 1px;
			}
		}

		.alert-secondary {
			margin-top: 1em;
			line-height: 2;
		}
	}
}
</style>
